<block name="style">
    <style type="text/css">
         .ajax-form{ overflow: hidden;}
         .ajax-form .form-div{ overflow: hidden; margin-bottom: 10px;}
         .ajax-form .form-div .left{ text-align: right;}
         .is_confirm_text{ font-size: 18px; text-align: center;}
         .is_confirm_box input{ width: 50%; float: left;}
         .modal-dialog{width:70%;}
    </style>
</block>
<!-- 模态框HTML -->
<form class="ajax-form" method="post" action="#">
    <notempty name="progress">
        <div class="form-div">
            <div class="col-md-11">订单id为{$order['id']}的进度信息(所属用户id:{$order['user_id']})</div>
        </div>
        <table class="table table-bordered table-striped table-hover" id="table-data">
            <!-- 表头 -->
            <thead>
                <tr>
                <if condition="$order['status'] eq 1">
                    <th class="row-selected" style="width: 20px"> <input class="check-all" type="checkbox"> </th>
                </if>
                    <th>操作人id</th>
                    <th>用户名</th>
                    <th>进度状态</th>
                    <th>操作备注</th>
                    <th>操作时间</th>
                </tr>
            </thead>
            <!-- 列表 -->
            <tbody class="progress-tbody">
            <foreach name="progress" item="row">
                    <tr>
                    <if condition="$order['status'] eq 1">
                        <td><input class="modal_ids" type="checkbox" value="{$row['id']}" name="modal_ids[]"></td>
                    </if>
                        <td>{$row['user_id']}</td>
                        <td>{$row['username']}</td>
                        <td>{$row['status']}</td>
                        <td>{$row['content']}</td>
                        <td><php> echo date('Y-m-d H:i:s',$row['create_time']) </php></td>
                    </tr>
            </foreach>
            </tbody>
        </table>
        <div class="form-div" style="border-bottom: 1px solid #ccc; padding-bottom: 5px;">
            <div class="col-md-1">
                <if condition="$order['status'] eq 1">
                    <input class="btn del_progress" type="button" value="删除">
                </if>
            </div>
            <div class="col-md-3"></div>
            <input class="col-md-1 btn page-up" style="display:none;width:auto;" type="button" value="上一页">
            <div class="col-md-1" style="margin-top:6px;width:auto;">第&nbsp;<span id="nowpage">{$pageinfo['page']}</span>&nbsp;页</div>
            <input class="col-md-1 btn page-down" style="width:auto;" type="button" value="下一页">
            <div class="col-md-1"></div>
            <div class="col-md-1" style="margin-top:6px;">共&nbsp;{$pageinfo['total']}&nbsp;页</div>
        </div> 

    <else />
        <div class="form-div">
            <div class="col-md-11 ">此订单暂时没有进度信息</div>
        </div>
    </notempty>

    <if condition="$order['status'] eq 1">
    <div class="form-div">
        <div class="col-md-1">
            <input type="button" value="新增" class="btn open_add_progress">
        </div>
    </div>
    </if>
    <div class="add_form" style="display:none;">
        <div class="form-div">
            <div class="col-md-2 left">
            进度状态：
            </div>
            <div class="col-md-9 left">
                <input type="text" class="form-control" name="progress_status">
            </div>
        </div>
        <div class="form-div">
            <div class="col-md-2 left">
            操作备注：
            </div>
            <div class="col-md-9 left">
                <input type="text" class="form-control" name="progress_content">
            </div>
        </div>
        <div class="form-div">
            <div class="col-md-6 left">
                <input type="button" value="提交" class="btn btn-primary add_progress">
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function(){
            //切换显示
            $('.open_add_progress').click(function(){
                $('.add_form').toggle();
            });

            var totalPage = "{$pageinfo['total']}";
            if(totalPage == 1){
                $('.page-down').hide();
            }
            //上一页
            $('.page-up').click(function () {
                var page = $('#nowpage').html()-1;
                if(page>0){
                    $(this).val('加载中..');
                    $(this).attr('disabled','disabled');
                    get_progress_list(page);
                }else{
                    alert('页数出错，请刷新重试。');
                }
            });

            //下一页
            $('.page-down').click(function () {
                var page = parseInt($('#nowpage').html())+1;
                if(page < (totalPage+1)){
                    $(this).val('加载中..');
                    $(this).attr('disabled','disabled');
                    get_progress_list(page);
                }else{
                    alert('页数出错，请刷新重试。');
                }
            });

            function get_progress_list(page){
                var r = 10;
                var order_id = "{$order['id']}";
                $.post('{:U('shop/true_order_progress')}',{page:page, r:r, order_id:order_id}, function (ret) {
                    if(ret.status==1){
                        var html="";
                        var order_status = "{$order['status']}";
                        if(ret.info){
                            ret.info.forEach(function(row){  
                                html += "<tr>";
                                if(order_status == 1){
                                    html += "<td><input class='modal_ids' type='checkbox' value='"+row.id+"' name='modal_ids[]'></td>";
                                }
                                html += "<td>"+row.user_id+"</td><td>"+row.username+"</td><td>"+row.status+"</td><td>"+row.content+"</td><td>"+row.create_time+"</td></tr>";
                            });
                            $('.progress-tbody').html(html);
                            $('.page-up').val('上一页');
                            $('.page-down').val('下一页');
                            $('#nowpage').html(page);
                            if(page == 1){
                                $('.page-up').hide();
                                $('.page-down').show();
                                $('.page-down').attr('disabled',false);
                            }else if(page == totalPage){
                                $('.page-down').hide();
                                $('.page-up').show();
                                $('.page-up').attr('disabled',false);
                            }else{
                                $('.page-up').show();
                                $('.page-down').show();
                                $('.page-up').attr('disabled',false);
                                $('.page-down').attr('disabled',false);
                            }
                        }else{
                            alert('页数出错，请刷新重试。');
                        }
                    }
                })
            }

            //新增进度
            $('.add_progress').click(function(){
                $(this).val('新增中..');
                var status = $("input[name='progress_status']").val();
                var content = $("input[name='progress_content']").val();
                var order_id = "{$order['id']}";
                $.post("{:U('shop/true_order_progress',array('action'=>'add'))}",{
                    order_id:order_id,
                    status:status, 
                    content:content,
                }, function (ret) {
                    if(ret.status==1){
                        alert('新增成功。');
                        $('.modal-backdrop').hide();
                        $('.close').click();
                        $("[modal-url='/index.php?s=/admin/shop/true_order_progress/order_id/{$order['id']}.html']").click();
                    }else{
                        alert('新增失败。请刷新重试');
                    }
                });
            });

            //全选
            $(".check-all").click(function () {
                $(".modal_ids").prop("checked", this.checked);
            });

            //删除进度信息
            $('.del_progress').click(function(){
                if($(".modal_ids:checked").length == 0){
                    alert('请先选择要删除的记录');
                }else if(confirm('确定删除吗？')){
                    $(this).html('正在删除..');
                    var ids = '';
                    $(".modal_ids:checked").each(function(index){  
                        ids += $(this).val();
                        if(index < $(".modal_ids:checked").length-1){
                            ids += ",";
                        }
                    });
                    $.post("{:U('shop/true_order_progress',array('action'=>'delete'))}",{ids:ids}, function (ret) {
                        if(ret.status==1){
                            alert('删除成功。');
                            $('.modal-backdrop').hide();
                            $('.close').click();
                            $("[modal-url='/index.php?s=/admin/shop/true_order_progress/order_id/{$order['id']}.html']").click();
                        }else{
                            alert('删除失败。请刷新重试');
                        }
                    });
                };
            });
        });
    </script>
</form>
